<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户编号" prop="userId" v-if="false">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登录账号" prop="loginAccount">
        <el-input
          v-model="queryParams.loginAccount"
          placeholder="请输入登录账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="真实姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入真实姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总做题数" prop="todayAllSubject" v-if="false">
        <el-input
          v-model="queryParams.todayAllSubject"
          placeholder="请输入今日总做题数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="错题数" prop="todayWrongSubject" v-if="false">
        <el-input
          v-model="queryParams.todayWrongSubject"
          placeholder="请输入今日错题数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="切出次数" prop="todayCutOutNumber" v-if="false">
        <el-input
          v-model="queryParams.todayCutOutNumber"
          placeholder="请输入今日切出次数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="切出时长" prop="todayCutOutTime" v-if="false">
        <el-input
          v-model="queryParams.todayCutOutTime"
          placeholder="请输入今日切出时长"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="正确率" prop="todayAccuracy" v-if="false">
        <el-input
          v-model="queryParams.todayAccuracy"
          placeholder="请输入今日正确率"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学习时长" prop="todayLearnTime" v-if="false">
        <el-input
          v-model="queryParams.todayLearnTime"
          placeholder="请输入今日学习时长"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间分" prop="timeScore" v-if="false">
        <el-input
          v-model="queryParams.timeScore"
          placeholder="请输入时间分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="能力分" prop="capacityScore" v-if="false">
        <el-input
          v-model="queryParams.capacityScore"
          placeholder="请输入能力分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创新分" prop="innovateScore" v-if="false">
        <el-input
          v-model="queryParams.innovateScore"
          placeholder="请输入创新分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专注分" prop="fengrossmentScore" v-if="false">
        <el-input
          v-model="queryParams.fengrossmentScore"
          placeholder="请输入专注分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="综合分" prop="synthesizeScore">
        <el-input
          v-model="queryParams.synthesizeScore"
          placeholder="请输入综合分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除状态 0未删除(默认) 1已删除" prop="isDel" v-if="false">
        <el-input
          v-model="queryParams.isDel"
          placeholder="请输入删除状态 0未删除(默认) 1已删除"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登录时间" prop="lastLoginTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.lastLoginTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择最后登录时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" v-if="false">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['receipt:statisAnalysis:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['receipt:statisAnalysis:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['receipt:statisAnalysis:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['receipt:statisAnalysis:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="analysisList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" v-if="false"/>
      <el-table-column label="用户编号" align="center" prop="userId" v-if="false"/>
      <el-table-column label="登录账号" align="center" prop="loginAccount" />
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="今日总做题数" align="center" prop="todayAllSubject" v-if="false"/>
      <el-table-column label="今日错题数" align="center" prop="todayWrongSubject" v-if="false"/>
      <el-table-column label="今日切出次数" align="center" prop="todayCutOutNumber" v-if="false"/>
      <el-table-column label="今日切出时长" align="center" prop="todayCutOutTime" v-if="false"/>
      <el-table-column label="今日正确率" align="center" prop="todayAccuracy" v-if="false"/>
      <el-table-column label="今日学习时长" align="center" prop="todayLearnTime" v-if="false"/>
      <el-table-column label="时间分" align="center" prop="timeScore" v-if="false"/>
      <el-table-column label="能力分" align="center" prop="capacityScore" v-if="false"/>
      <el-table-column label="创新分" align="center" prop="innovateScore" v-if="false"/>
      <el-table-column label="专注分" align="center" prop="fengrossmentScore" v-if="false"/>
      <el-table-column label="综合分" align="center" prop="synthesizeScore" />
      <el-table-column label="删除状态 0未删除(默认) 1已删除" align="center" prop="isDel" :formatter="isDelFormat" v-if="false"/>
      <el-table-column label="最后登录时间" align="center" prop="lastLoginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastLoginTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" v-if="false"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="false">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['receipt:statisAnalysis:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['receipt:statisAnalysis:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改统计分析对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户编号" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户编号" />
        </el-form-item>
        <el-form-item label="登录账号" prop="loginAccount">
          <el-input v-model="form.loginAccount" placeholder="请输入登录账号" />
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="今日总做题数" prop="todayAllSubject">
          <el-input v-model="form.todayAllSubject" placeholder="请输入今日总做题数" />
        </el-form-item>
        <el-form-item label="今日错题数" prop="todayWrongSubject">
          <el-input v-model="form.todayWrongSubject" placeholder="请输入今日错题数" />
        </el-form-item>
        <el-form-item label="今日切出次数" prop="todayCutOutNumber">
          <el-input v-model="form.todayCutOutNumber" placeholder="请输入今日切出次数" />
        </el-form-item>
        <el-form-item label="今日切出时长" prop="todayCutOutTime">
          <el-input v-model="form.todayCutOutTime" placeholder="请输入今日切出时长" />
        </el-form-item>
        <el-form-item label="今日正确率" prop="todayAccuracy">
          <el-input v-model="form.todayAccuracy" placeholder="请输入今日正确率" />
        </el-form-item>
        <el-form-item label="今日学习时长" prop="todayLearnTime">
          <el-input v-model="form.todayLearnTime" placeholder="请输入今日学习时长" />
        </el-form-item>
        <el-form-item label="时间分" prop="timeScore">
          <el-input v-model="form.timeScore" placeholder="请输入时间分" />
        </el-form-item>
        <el-form-item label="能力分" prop="capacityScore">
          <el-input v-model="form.capacityScore" placeholder="请输入能力分" />
        </el-form-item>
        <el-form-item label="创新分" prop="innovateScore">
          <el-input v-model="form.innovateScore" placeholder="请输入创新分" />
        </el-form-item>
        <el-form-item label="专注分" prop="fengrossmentScore">
          <el-input v-model="form.fengrossmentScore" placeholder="请输入专注分" />
        </el-form-item>
        <el-form-item label="综合分" prop="synthesizeScore">
          <el-input v-model="form.synthesizeScore" placeholder="请输入综合分" />
        </el-form-item>
        <el-form-item label="删除状态 0未删除(默认) 1已删除" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入删除状态 0未删除(默认) 1已删除" />
        </el-form-item>
        <el-form-item label="最后登录时间" prop="lastLoginTime">
          <el-date-picker clearable size="small"
            v-model="form.lastLoginTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择最后登录时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAnalysis, getAnalysis, delAnalysis, addAnalysis, updateAnalysis, exportAnalysis } from "@/api/analysis/analysis";

export default {
  name: "Analysis",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 统计分析表格数据
      analysisList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 删除状态 0未删除(默认) 1已删除字典
      isDelOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        loginAccount: null,
        realName: null,
        todayAllSubject: null,
        todayWrongSubject: null,
        todayCutOutNumber: null,
        todayCutOutTime: null,
        todayAccuracy: null,
        todayLearnTime: null,
        timeScore: null,
        capacityScore: null,
        innovateScore: null,
        fengrossmentScore: null,
        synthesizeScore: null,
        isDel: null,
        lastLoginTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_delete_status").then(response => {
      this.isDelOptions = response.data;
    });
  },
  methods: {
    /** 查询统计分析列表 */
    getList() {
      this.loading = true;
      listAnalysis(this.queryParams).then(response => {
        this.analysisList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 删除状态 0未删除(默认) 1已删除字典翻译
    isDelFormat(row, column) {
      return this.selectDictLabel(this.isDelOptions, row.isDel);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        loginAccount: null,
        realName: null,
        todayAllSubject: null,
        todayWrongSubject: null,
        todayCutOutNumber: null,
        todayCutOutTime: null,
        todayAccuracy: null,
        todayLearnTime: null,
        timeScore: null,
        capacityScore: null,
        innovateScore: null,
        fengrossmentScore: null,
        synthesizeScore: null,
        isDel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        lastLoginTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加统计分析";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAnalysis(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改统计分析";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAnalysis(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAnalysis(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除统计分析编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAnalysis(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有统计分析数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportAnalysis(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
